<?php

namespace app\common;

use app\common\RenderJson;
use think\Cache;

class BaseAPIController extends BaseController {
	protected $token = null;
	protected $account = null;
	public function _initialize() {
		parent::_initialize ();
		$this->token = $this->request->header ( 'token', false );
		// 初始化的时候检查用户是否登录
		if (! $this->token) {
			self::noLogin ();
		}
		$this->account = Cache::get ( $this->token );
		if (! $this->account) {
			self::noLogin ();
		}
	}
	/**
	 * 用户未登录
	 */
	private function noLogin() {
		echo new RenderJson ( false, '未找到登录信息' );
		exit ();
	}
}